function plot_t(V,T,Z)
%  plot_t(V,T,Z)
%This is a matlab program to plot a triangulation for given vertices in V
%and a list T of triangles by the index of vertices in V. If the triangulation of
%3D surface, Z should be provided.
% This matlab program is copyrighted @2001 by Ming-Jun Lai and Paul Wenston
% through University of Georgia Research Foundation, Inc.
 [m,n]=size(T);
 TRI=zeros(m,6);
 if nargin==2
 for i=1:m
   TRI(i,:)=[V(T(i,1),:),V(T(i,2),:),V(T(i,3),:)];
 end;
 x=TRI(:,1:2:5);
 y=TRI(:,2:2:6);
 xmax=max(max(x));xmin=min(min(x));
 ymax=max(max(y));ymin=min(min(y));
 axis([xmin, xmax, ymin, ymax]);
 X=[x,x(:,1)]';Y=[y,y(:,1)]';
 plot(X,Y,'b','LineWidth',0.2);axis equal
else
    TRI=zeros(m,9);
    V=[V Z]; 
    for i=1:m
   TRI(i,:)=[V(T(i,1),:),V(T(i,2),:),V(T(i,3),:)];
 end;
 x=TRI(:,1:3:9);
 y=TRI(:,2:3:9); z=TRI(:,3:3:9);
 xmax=max(max(x));xmin=min(min(x));
 ymax=max(max(y));ymin=min(min(y));
 zmax=max(max(z));zmin=min(min(z));
 axis([xmin, xmax, ymin, ymax, zmin, zmax]);
 X=[x,x(:,1)]';Y=[y,y(:,1)]'; Z=[z,z(:,1)]';
 plot3(X,Y,Z,'b','LineWidth',0.2);axis equal
end
